<!doctype html>
<html>
<head>
<include file="Include:meta" />
<title>编辑人员需求-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<style>
	.form-item .input-label{ width: 160px !important; }
	.input-prompt{ display: block; color: #999; line-height: 18px }
	.w50{ width: 50px }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">人员需求管理 > 编辑人员需求</div>
	</div>
	<div id="content">
		<form action="__APP__/Hr/person_demand_edit" method="post" enctype="multipart/form-data">
			<input type="hidden" name="action" value="edit">
			<input type="hidden" name="id" value="{$result['id']}">
			<div class="form-main">
				<div class="form-title">编辑人员需求</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>申请职位</div>
					<div class="input-item">
						<select name="position" class="form-control w300" autocomplete="off">
							<option value="-10">请选择</option>
							<foreach name="result_position" item="vo">
							<option value="{$vo['position_id']}" <if condition="$result['position'] eq $vo['position_id']">selected</if>>{$vo['position_descr']}</option>
							</foreach>
						</select>
						<input type="text" name="position_new" value="{$result['position_new']}" <if condition="$result['position'] eq NULL">class="form-control"<else />class="form-control hide"</if> autocomplete="off">
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>申请人数</div>
					<div class="input-item">
						<input type="text" name="number" value="{$result['number']}" class="form-control" autocomplete="off">
						<span class="error-item">必填项</span><span class="error-item">必需为正整数</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>岗位职级</div>
					<div class="input-item">
						<input type="text" name="rank" value="{$result['rank']}" class="form-control required-text" autocomplete="off">
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>汇报对象</div>
					<div class="input-item">
						<select name="report_uid" class="form-control w100 required-selted">
							<option value="-10">请选择</option>
							<foreach name="result1" item="vo">
							<option value="{$vo['id']}" <if condition="$result['report_uid'] eq $vo['id']">selected</if>>{$vo['username']}</option>
							</foreach>
						</select>
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>岗位所属部门</div>
					<div class="input-item">
						<select name="department" class="form-control required-selted w300" autocomplete="off">
							<option value="-10" selected>请选择</option>
							<foreach name="result_department" item="vo">
							<option value="{$vo['DEPTID']}" <if condition="$result['department'] eq $vo['DEPTID']">selected</if>>{$vo['HPS_DEPT_FULLDESCR']}</option>
							</foreach>
						</select>
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">是否关键岗位</div>
					<div class="input-item">
						<span class="checkbox-item">
							<label class="radio-inline"><input type="radio" name="is_position" value="是" <if condition="$result['is_position'] eq '是'">checked</if>>是</label>
							<label class="radio-inline"><input type="radio" name="is_position" value="否" <if condition="$result['is_position'] eq '否'">checked</if>>否</label>
						</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>申请日期</div>
					<div class="input-item">
						<input type="text" name="sq_date" value="{$result['sq_date']}" class="form-control Wdate w100 required-text" onclick="WdatePicker()" readonly="" autocomplete="off">
						<span class="error-item" style="display: none;">必填项</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>申请原因</div>
					<div class="input-item">
						<textarea name="sq_remark" class="form-control w400 required-text" autocomplete="off">{$result['sq_remark']}</textarea>
						<span class="error-item">必填项</span>
					</div>
				</div>
				<div class="form-table-item">
					<table class="table">
						<tr class="form-table-header Text_c">
							<td colspan="3">申请理由</td>
						</tr>
						<tr>
							<td width="280" class="title-box"><b>岗位职责简述及工作时间占比（%）</b></td>
							<td>
								<textarea name="reason1" class="form-control w400" autocomplete="off">{$result['reason1']}</textarea>
							</td>
							<td width="320">
								<b>是否后附材料</b>
								<span class="checkbox-item ml10">
									<label class="radio-inline"><input type="radio" name="file1" value="是" <if condition="$result['file1'] eq '是'">checked</if>>是</label>
									<label class="radio-inline"><input type="radio" name="file1" value="否" <if condition="$result['file1'] eq '否'">checked</if>>否</label>
								</span>
								<div <if condition="$result['file1'] eq '是'">class="filebox filecur"<else />class="filebox hide"</if>>
									<div class="input-group w250 left">
										<input type="text" name="file_name1" value="{$result['file_name1']}" class="form-control file-name" <if condition="$result['file1'] neq '是'">readonly</if> placeholder="请上传附件" autocomplete="off">
										<span class="input-group-btn">
											<button class="btn file-submit" type="button">上传</button>
										</span>
									</div>
									<button <if condition="$result['file1'] neq '是'">class="btn file-delete ml5 hide"<else />class="btn file-delete ml5"</if> type="button">删除</button>
									<input type="hidden" name="file_url1" value="{$result['file_url1']}" class="file-url" autocomplete="off">
									<span class="error-item">文件名必填</span>
									<span class="error-item" style="white-space: nowrap;">请上传文件</span>
								</div>
							</td>
						</tr>
						<tr>
							<td class="title-box"><b>岗位任职要求</b><span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign mr5"></i><em style="font-style:normal;">如后附材料，可不用填写</em></span></td>
							<td>
								<p>基本要求：</p>
								<p class="mb10">学历：<input type="text" name="requir1" value="{$result['requir1']}" class="form-control w100 mr10" autocomplete="off">专业：<input type="text" name="requir2" value="{$result['requir2']}" class="form-control w100 mr10" autocomplete="off">年龄：<input type="text" name="requir3" value="{$result['requir3']}" class="form-control w50 year" autocomplete="off"> — <input type="text" name="requir4" value="{$result['requir4']}" class="form-control w50 mr5 year" autocomplete="off">周岁<span class="ml10">性别：<input type="text" name="requir5" value="{$result['requir5']}" class="form-control w100" autocomplete="off"></span></p>
								<span class="error-item sp sp1">年龄必需为正整数</span><span class="error-item sp sp2">请填写结束年龄段</span><span class="error-item sp sp3">请填写开始年龄段</span>
								<p>任职资格：</p>
								<textarea name="reason2" class="form-control w400" autocomplete="off">{$result['reason2']}</textarea>
							</td>
							<td>
								<b>是否后附材料</b>
								<span class="checkbox-item ml10">
									<label class="radio-inline"><input type="radio" name="file2" value="是" <if condition="$result['file2'] eq '是'">checked</if>>是</label>
									<label class="radio-inline"><input type="radio" name="file2" value="否" <if condition="$result['file2'] eq '否'">checked</if>>否</label>
								</span>
								<div <if condition="$result['file2'] eq '是'">class="filebox filecur"<else />class="filebox hide"</if>>
									<div class="input-group w250 left">
										<input type="text" name="file_name2" value="{$result['file_name2']}" class="form-control file-name" <if condition="$result['file2'] neq '是'">readonly</if> placeholder="请上传附件" autocomplete="off">
										<span class="input-group-btn">
											<button class="btn file-submit" type="button">上传</button>
										</span>
									</div>
									<button <if condition="$result['file2'] neq '是'">class="btn file-delete ml5 hide"<else />class="btn file-delete ml5"</if> type="button">删除</button>
									<input type="hidden" name="file_url2" value="{$result['file_url2']}" class="file-url" autocomplete="off">
									<span class="error-item">文件名必填</span>
									<span class="error-item" style="white-space: nowrap;">请上传文件</span>
								</div>
							</td>
						</tr>
						<tr>
							<td class="title-box"><b>关键业绩指标（KPI）</b><span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign mr5"></i><em style="font-style:normal;">如内容较多，后附材料，可不用填写</em></span></td>
							<td>
								<textarea name="reason3" class="form-control w400" autocomplete="off">{$result['reason3']}</textarea>
							</td>
							<td>
								<b>是否后附材料</b>
								<span class="checkbox-item ml10">
									<label class="radio-inline"><input type="radio" name="file3" value="是" <if condition="$result['file3'] eq '是'">checked</if>>是</label>
									<label class="radio-inline"><input type="radio" name="file3" value="否" <if condition="$result['file3'] eq '否'">checked</if>>否</label>
									<span class="error-item" style="display: none;">必填项</span>
								</span>
								<div <if condition="$result['file3'] eq '是'">class="filebox filecur"<else />class="filebox hide"</if>>
									<div class="input-group w250 left">
										<input type="text" name="file_name3" value="{$result['file_name3']}" class="form-control file-name" <if condition="$result['file3'] neq '是'">readonly</if> placeholder="请上传附件" autocomplete="off">
										<span class="input-group-btn">
											<button class="btn file-submit" type="button">上传</button>
										</span>
									</div>
									<button <if condition="$result['file3'] neq '是'">class="btn file-delete ml5 hide"<else />class="btn file-delete ml5"</if> type="button">删除</button>
									<input type="hidden" name="file_url3" value="{$result['file_url3']}" class="file-url" autocomplete="off">
									<span class="error-item">文件名必填</span>
									<span class="error-item" style="white-space: nowrap;">请上传文件</span>
								</div>
							</td>
						</tr>
						<tr>
							<td class="title-box"><b>岗位客户</b><span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign mr5"></i><em style="font-style:normal;">岗位人员对接的对象（如人力资源部/招聘专员岗：对接各事业部人员等）</em></span></td>
							<td colspan="2">
								<textarea name="reason4" class="form-control w400" autocomplete="off">{$result['reason4']}</textarea>
							</td>
						</tr>
						<tr>
							<td class="title-box"><b>岗位出勤率</b><span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign mr5"></i><em style="font-style:normal;">说明同岗位已有人员前3~6个月出勤率情况/新增岗位填写无，需员工关系组确认</em></span></td>
							<td colspan="2">
								<textarea name="reason5" class="form-control w400" autocomplete="off">{$result['reason5']}</textarea>
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="form-btn-item"><button class="btn submit" type="submit">提交</button><button class="btn btn-default goback" type="button">返回</button></div>
		</form>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript">
$(function(){
	KindEditor.ready(function(K){
		//上传附件
		var editorFile = K.editor();
		$('.file-submit').on('click',function(){
			var parents = $(this).parents(".input-group");
			editorFile.loadPlugin('insertfile',function(){
				document.cookie="file_name=person_demand";
				document.cookie="file_type=ppt,pptx,pdf,doc,docx,jpg,jpeg,png,xls,xlsx,txt,rar,zip";
				editorFile.plugin.fileDialog({
					clickFn:function(url,title){
						parents.nextAll(".error-item").hide();
						parents.find(".file-name").val(title).prop("readonly",false);
						parents.nextAll(".file-url").val(url);
						parents.nextAll(".file-delete").show();
						editorFile.hideDialog();
					}
				});
			});
		});
	});
	
	//删除附件
	$(".file-delete").click(function(){
		$(this).hide();
		$(this).nextAll(".error-item").hide();
		$(this).nextAll(".file-url").val("");
		$(this).prevAll(".input-group").find(".file-name").val("").prop("readonly",true);
	});
	//输入框显示隐藏
	$("[name='position']").change(function(){
		if($(this).val()==-10){
			$(this).siblings(":text").show();
		}else{
			$(this).siblings(":text").val("").hide();
		}
		$(this).nextAll(".error-item").hide();
	});
	//标签选择事件
	$("select.select-add").on('change',function(){
		var val = $(this).val(),
			text = $(this).nextAll(".select-add-text");
		if(val==-10){
			text.show();
		}else{
			text.hide().val("").nextAll(".error-item").hide();
		}
	});
	$('table .radio-inline').click(function(){
		var val = $(this).find('input:checked').val();
		if(val=="是"){
			$(this).parents('td').find('.filebox').addClass('filecur').show();
		}else{
			$(this).parents('td').find('.filebox').removeClass('filecur').hide();
			$(this).parents('td').find('.file-name').val('').attr("readonly","readonly");
			$(this).parents('td').find('.file-url').val('');
			$(this).parents('td').find('.file-delete').hide();
			$(this).parents('td').find('.error-item').hide();
		}
	})
	//添加类型多选框
	$('.label-add-btn').on('click',function(){
		var input = $(this).prevAll(".label-add-text").eq(0),
			item = input.prev(".checkbox-item"),
			val = input.val(),
			tag = true;
		input.nextAll(".error-item").eq(1).hide();
		if(val=="" || /^\s+$/.test(val)){
			input.nextAll(".error-item").eq(0).show();
			tag = false;
		}if(val=="全部"){
			input.nextAll(".error-item").eq(2).show();
			tag = false;
		}else{
			item.find(".checkbox-inline").each(function(){
				if($(this).text()==val){
					input.nextAll(".error-item").eq(2).show();
					tag = false;
					return false;
				}
			});
		}
		
		if(tag){
			var first_id = $(this).attr("first_id"),
				label = item.find(".checkbox-inline:last"),
				name = label.find(":checkbox").attr("name");
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:{"type_name":val,"first_id":first_id},
				url:"__APP__/Index/label_add_ajax",
				success:function(data){
					if(data.id){
						input.val("");
						item.find(".error-item").hide();
						var html = "<label class='checkbox-inline'><input type='checkbox' name="+name+" value="+data.id+" checked autocomplete='off'>"+data.name+"</label>";
						label.after(html);
					}
				}
			});
		}
	});
	
	//表单验证
	$(".submit").click(function(){
		var tag = false;
		
		$('.required-selted').each(function(){
			var val = $(this).val();
			if(val == -10){
				tag = true;
				$(this).siblings('.error-item').show();
			}
		})
		$('.required-text').each(function(){
			var val = $(this).val();
			if(val == ''){
				tag = true;
				$(this).siblings('.error-item').show();
			}
		})
		$("[name='number']").each(function(){
			var val = $(this).val();
			if(val!="" && !/^[1-9]\d*$/.test(val)){
				$(this).nextAll(".error-item").eq(1).show();
				tag = true;
			}
			if(val==''){
				$(this).next(".error-item").show();
				tag = true;
			}
		})
		$("[name='position']").each(function(){
			var $val = $(this).val();
			
			if($val==-10 && $(this).siblings(":text").val()==""){
				$(this).nextAll(".error-item").eq(0).show();
				tag = true;
			}
		});
		$(".year").each(function(){
			var val = $(this).val();
			if(val!="" && !/^[1-9]\d*$/.test(val)){
				$(".sp").show();
				tag = true;
			}
			if($('.year').eq(0).val()!='' && $('.year').eq(1).val()==''){
				$(".sp2").show();
				tag = true;
			}
			if($('.year').eq(0).val()=='' && $('.year').eq(1).val()!=''){
				$(".sp3").show();
				tag = true;
			}
		})
		$('.filecur').each(function(){
			var val = $(this).find('.file-name').val();
			if(val==''){
				$(this).find('.error-item').eq(1).show();
				tag = true;
			}
		})
		if(tag){
			return false;
		}
	});

	//取消错误提示
	$(".required-text,[name='number']").blur(function(){
		$(this).nextAll(".error-item").hide();
	});
	$(".year").blur(function(){
		$('.sp').hide();
	});
	$(".required-selted").change(function(){
		$(this).nextAll(".error-item").hide();
	});
	$("[name='position']").siblings(":text").focus(function(){
		$(this).nextAll(".error-item").hide();
	});
});
</script>
</body>
</html>